package com.leeoohoo.base;

import com.leeoohoo.enums.ResultEnum;
import lombok.Data;

/**
 * @Description:
 * @Author: lei.d.li@capgemini.com
 * @CreateTime: 2023/2/1
 */
@Data
public class Result<T> {

    private String message;

    private Integer code;

    private T data;

    private Result(String message, Integer code, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private Result(ResultEnum resultEnum, T data) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.data = data;
    }

    private Result(ResultEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.message = resultEnum.getMessage();
    }


    public static Result success() {
        return new Result(ResultEnum.SUCCESS);
    }

    public static <T> Result success(T data) {
        return new Result(ResultEnum.SUCCESS, data);
    }


    public static Result fail() {
        return new Result(ResultEnum.FAIL);
    }

    public static Result fail(Object data) {
        return new Result(ResultEnum.FAIL, data);
    }

    public static Result other(ResultEnum resultEnum) {
        return new Result(resultEnum);
    }

    public static Result other(ResultEnum resultEnum, Object data) {
        return new Result(resultEnum, data);
    }


}
